package StackAndQueue;

import java.util.Arrays;
import java.util.LinkedList;

public class p1047删除字符串中所有相邻的重复项 {
    class Solution {
        public String removeDuplicates(String s) {
            LinkedList<Character> stack = new LinkedList<>();
            for (int i = 0; i < s.length(); i++) {
                if (stack.peek() != null && s.charAt(i) == stack.peek()){
                    stack.pop();
                } else {
                    stack.push(s.charAt(i));
                }
            }
            String ans = "";
            while (!stack.isEmpty()){
                ans = stack.pop() + ans;
            }
            return ans;
        }
    }
}
